package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Borrow implements IOperation{

    @Override
    public void work (BookList bookList) {
        System.out.println ("借阅图书");
        System.out.println ("输入要借阅的书：");
        Scanner p=new Scanner (System.in);
        String name=p.nextLine ();
        int current=bookList.getUsedSize ();
        for (int i = 0; i < current; i++) {
            Book now=bookList.getBooks (i);
            if(now.getName ().equals (name)){
                if(!now.isBorrowed ()){
                    now.setB0rrowed (true);
                    System.out.println ("借书成功");
                }else{
                    System.out.println ("该书已经被借出");
                }
                //return语句的加入可以不执行后续的语句
                return;
            }
        }
        System.out.println ("不存在你要借的书");
    }
}
